﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Wiki.WinClient
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
           
        }
        //磁性窗体实现《下》
        SearchContentForm form = new SearchContentForm();  //new一个窗体2的对象jishiben；
        public static bool _Start = true;     //定义一个变量_start为true；
        public static int _x, _y;
        //定义两个int变量实现x轴y轴计算；
        //磁性窗体实现《上》
        private Point mouseOffset;        //记录鼠标指针的坐标

        private bool isMouseDown = false; //记录鼠标按键是否按下

        private void form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {

            int xOffset;

            int yOffset;

            if (e.Button == MouseButtons.Left)
            {

                xOffset = -e.X;// -SystemInformation.FrameBorderSize.Width;

                yOffset = -e.Y;// -SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;

                mouseOffset = new Point(xOffset, yOffset);

                isMouseDown = true;

            }

        }

        private void form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {

            if (isMouseDown)
            {

                Point mousePos = Control.MousePosition;

                mousePos.Offset(mouseOffset.X, mouseOffset.Y);

                Location = mousePos;

            }

        }

        private void form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {

            // 修改鼠标状态isMouseDown的值

            // 确保只有鼠标左键按下并移动时，才移动窗体

            if (e.Button == MouseButtons.Left)
            {

                isMouseDown = false;

            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
          //  this.BackgroundImage = global::Wiki.WinClient.Properties.Resources.contentbg;
            _x = this.Location.X;// +this.Width;      //变量_x等于窗体x轴大小；
            _y = this.Location.Y + this.Height;                   //变量_y等于窗体y轴大小；
            form.Location = new Point(_x, _y); //初始化窗体的大小，相当于自定义；
           form.Show();
            
        }
       
        private void MainForm_Load(object sender, EventArgs e)
        {
            _x = this.Location.X;// +this.Width;      //变量_x等于窗体x轴大小；
            _y = this.Location.Y + this.Height;                   //变量_y等于窗体y轴大小；
            form.Location = new Point(_x, _y); //初始化窗体的大小，相当于自定义；
           // form.Show();

            
            //form.Show();
            ////初始化调用不规则窗体生成代码
            //BitmapRegion BitmapRegion = new BitmapRegion();//此为生成不规则窗体和控件的类
            //BitmapRegion.CreateControlRegion(this, new Bitmap("Resources/barbg.bmp"));
           // BitmapRegion.CreateControlRegion(this, new Bitmap(GetType(), "Resources/barbg.bmp"));
           
        }
       
        private void MainForm_LocationChanged(object sender, EventArgs e)
        {
            _x = this.Location.X;// +this.Width;
            _y = this.Location.Y +this.Height;
            int temp = form.Location.X;//x
            if ((temp - _x) <= 30 && (temp - _x) >= 0)
                form.Location = new Point(_x, _y);
            if (!_Start)
                return;
            form.Location = new Point(_x, _y);
        }

        private void Obj_MouseHover(object sender, EventArgs e)
        {
            ((PictureBox)sender).BackColor = System.Drawing.Color.FromArgb(7, 38, 17);
           
        }

        private void Obj_MouseLeave(object sender, EventArgs e)
        {
            ((PictureBox)sender).BackColor = Color.Transparent;
        }
        int goX, goY;
        private void Obj_MouseDown(object sender, MouseEventArgs e)
        {
            goX = ((PictureBox)sender).Location.X;
            goY = ((PictureBox)sender).Location.Y;

            ((PictureBox)sender).Location = new Point(goX + 1, goY + 1);
        }

        private void Obj_MouseUp(object sender, MouseEventArgs e)
        {
            ((PictureBox)sender).Location = new Point(goX, goY);
        }

        private void SeachPicBox_Click(object sender, EventArgs e)
        {
            _x = this.Location.X;// +this.Width;      //变量_x等于窗体x轴大小；
            _y = this.Location.Y + this.Height;                   //变量_y等于窗体y轴大小；
            
            form.Location = new Point(_x, _y); //初始化窗体的大小，相当于自定义；
            form.Show();
        }

        private void ClosePicBox_Click(object sender, EventArgs e)
        {
            //Application.Exit();
            this.WindowState = FormWindowState.Minimized;
        }

        private void MainForm_SizeChanged(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.Hide();
                this.notifyIcon1.Visible = true;
            }
        }
        private void notifyIcon1_Click(object sender, EventArgs e)
        {
            this.Visible = true;

            this.WindowState = FormWindowState.Normal;

            //this.notifyIcon1.Visible = false;
        }

        private void 退出程序ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void AddPicBox_Click(object sender, EventArgs e)
        {
            ContentForm form = new ContentForm();
            form.Show();
        }

        private void SettingPicBox_Click(object sender, EventArgs e)
        {
            var form = new SettingForm();
            form.ShowDialog();
        }

       

                 


       

    }
}
